<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 同城模板库
 */
namespace app\allwin\model;
use think\Model;

class AllwinInfoMp extends Model{
    
    protected $pk    = 'id';
    protected $autoWriteTimestamp = true;
    
    //关联用户信息
    public function user(){
        return $this->hasOne('app\common\model\SystemUser','id','uid');
    }

    /**
     * 保存数据
     * @param  string $array 传入的保存数据的参数
     * @return json
     */
    public static function edit(array $param){
        $data = [
            'uid'       => $param['uid'],
            'logo'      => $param['logo'],
            'title'     => $param['title'],
            'note'      => $param['note'],
            'is_vip'    => $param['is_vip'],
            'vip_title' => $param['vip_title'],
            'vip_about' => $param['vip_about'],
            'vip_time'  => $param['vip_time']? strtotime($param['vip_time']):'',
            'reg_time'  => time()
        ];
        if(empty($param['id'])){
            $data['member_miniapp_id'] = $param['member_miniapp_id'];
            return self::insertGetId($data);
        }else{
            return self::where(['id' => $param['id']])->update($data);
        }        
    } 
}